package com.gc.framework.mybatisplus;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;

import com.gc.common.utils.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.gc.common.base.BaseEntity;
import com.gc.framework.util.ShiroUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @author sushengbuyu
 * @date 2019/1/24 16:16
 */
@Slf4j
public class CommonMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {}

    @Override
    public void updateFill(MetaObject metaObject) {}


    /**
     * 根据属性名获取属性值
     * 
     */
    private Object getFieldValueByName(String fieldName, Object o) {
        try {
            String firstLetter = fieldName.substring(0, 1).toUpperCase();
            String getter = "get" + firstLetter + fieldName.substring(1);
            Method method = o.getClass().getMethod(getter, new Class[]{});
            Object value = method.invoke(o, new Object[]{});
            if(StringUtils.isNull(value)){return "";}
            return value;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "";
        }
    }
}
